import { ref, reactive } from 'vue'
import { defineStore } from 'pinia'

// 定义 Store
export const listStore = defineStore(
  'listQueryStore',
  () => {
    // 订单查询tab
    const orderActiveTab = ref('short-order')
    const updateOrderActiveTab = (value: string) => {
      orderActiveTab.value = value
    }

    // 短租订单查询参数
    const sOrderQueryParam = reactive({
      sortField: 'orderStatus',
      sortType: 'asc',
    })
    // 更新短租订单查询参数
    const updateSOrderQueryParam = (newQueyParam: object) => {
      // 清空参数
      for (let key in sOrderQueryParam) {
        sOrderQueryParam[key] = undefined
      }
      Object.assign(sOrderQueryParam, { ...newQueyParam })
    }

    // 长租订单查询参数
    const lOrderQueryParam = reactive({
      sortField: 'status',
      sortType: 'asc',
    })
    // 更新长租订单查询参数
    const updateLOrderQueryParam = (newQueyParam: object) => {
      // 清空参数
      for (let key in lOrderQueryParam) {
        lOrderQueryParam[key] = undefined
      }
      Object.assign(lOrderQueryParam, { ...newQueyParam })
    }

    const clear = () => {
      updateSOrderQueryParam({ sortField: 'orderStatus', sortType: 'asc' })
      updateLOrderQueryParam({ sortField: 'status', sortType: 'asc' })
    }

    return {
      orderActiveTab,
      updateOrderActiveTab,
      sOrderQueryParam,
      updateSOrderQueryParam,

      lOrderQueryParam,
      updateLOrderQueryParam,
      clear,
    }
  },
  // {
  //   persist: [
  //     {
  //       paths: ['orderActiveTab'],
  //     },
  //   ],
  // },
)
